package com.lzq.framework.util.time;

import java.time.*;
import java.util.Date;

/**
 * @author 2019/7/11 11:21 by 刘赵强
 **/
public class TimeConvertUtils {
    private static ZoneId zone = ZoneId.systemDefault();

    public TimeConvertUtils() {
    }

    private static LocalDateTime convertToLocalDateTime(Instant instant) {
        return LocalDateTime.ofInstant(instant, zone);
    }

    public static Date convertToDate(LocalDateTime localDateTime) {
        Instant instant = localDateTime.atZone(zone).toInstant();
        return Date.from(instant);
    }

    public static Date convertToDate(LocalDate localDate) {
        Instant instant = localDate.atStartOfDay(zone).toInstant();
        return Date.from(instant);
    }

    public static LocalDate convertToLocalDate(Date date) {
        Instant instant = date.toInstant();
        return convertToLocalDateTime(instant).toLocalDate();
    }

    public static LocalTime convertToLocalTime(Date date) {
        Instant instant = date.toInstant();
        return convertToLocalDateTime(instant).toLocalTime();
    }

    public static LocalDateTime convertToLocalDateTime(Date date) {
        Instant instant = date.toInstant();
        return convertToLocalDateTime(instant);
    }
}
